package com.qidian.mes.produce.controller;

import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Material;
import com.qidian.mes.produce.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/23 9:17
 */
@RestController
@RequestMapping("/material")
@CrossOrigin
public class MaterialController {
    @Autowired
    MaterialService materialService;

    @GetMapping("/list")
    public MESResult getList(Material material,int craftRelId, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        return materialService.queryAllByRelId(material,craftRelId,page,limit);

    }

    @PostMapping("/add")
    public MESResult add(int materialRelId,int craftRelId){
        return materialService.addMaterial(materialRelId,craftRelId);
    }

    @GetMapping("/getAll")
    public MESResult getAll(){
        return materialService.getAll();
    }

    @GetMapping("/getPrimary")
    public MESResult getPrimary(int materialRelId,int craftRelId){
        return materialService.getPrimary(materialRelId,craftRelId);
    }

    @PutMapping("/primary")
    public MESResult primary(@RequestBody Material material){
        return materialService.primaryMaterial(material);
    }
}
